<?php

/*
 * GET ACTIVE YEAR
 */
 
	if ( ! function_exists('currentYear'))
	{
		function currentYear($get = '')
		{
			$_DB = new ConfigDB();
			
			$return = $_DB->selectDB2("SELECT `year_idPK`, `year_from`, `year_to`, `is_summer` FROM `tbl_year` WHERE `is_deleted` = 'N'");
			
			switch($get) {
				case 'id': 		return $return['year_idPK']; 	break;
				case 'from': 	return $return['year_from']; 	break;
				case 'to': 		return $return['year_to']; 		break;
				default: 		return $return; 				break;
			}
			
		}
	}

 
/*
 * HTML
 */

	if ( ! function_exists('br'))
	{
		function br($num = 1)
		{
			echo str_repeat("<br />", $num);
		}
	}

	if ( ! function_exists('nbsp'))
	{
		function nbsp($num = 1)
		{
			return str_repeat("&nbsp;", $num);
		}
	}

	if ( ! function_exists('firstUpperCase'))
	{
		function firstUpperCase($str)
		{
			return ucwords(strtolower($str));
		}
	}

	if ( ! function_exists('lowerCase'))
	{
		function lowerCase($str)
		{
			return strtolower($str);
		}
	}

	if ( ! function_exists('upperCase'))
	{
		function upperCase($str)
		{
			return strtoupper($str);
		}
	}

	if ( ! function_exists('nameFormat'))
	{
		function nameFormat($strFirstName, $strMiddleName, $strLastName)
		{
			if ( !empty($strMiddleName) )
				return ucwords(strtolower($strFirstName)) . ' ' . substr($strMiddleName, 0, 1) . '. ' . ucwords(strtolower($strLastName));
			else 
				return ucwords(strtolower($strFirstName)) . ' ' . ucwords(strtolower($strLastName));
		}
	}

	if ( ! function_exists('hashRandom'))
	{
		function hashRandom($str = '')
		{
			return str_replace(array('+', '/', '='), "", (base64_encode(addslashes(gzcompress(serialize($str),9)))));
		}
	}
	
	
	
	if ( ! function_exists('warning'))
	{
		function warning($str = 'Required Field.', $tag = 'span') {
				return '<'.$tag.' style="color:#F00;">'.$str.'</'.$tag.'>';
		}
	}
	
	if ( ! function_exists('priceFormat'))
	{
		function priceFormat($strVal) {
				return number_format($strVal, 2, '.', '');
		}
	}
	
	if ( ! function_exists('roundNumber'))
	{
		function removeDecimal($number_float){
			
			$num_split = explode(".",$number_float);
			
			return $num_split[0];
			
		}
	}
	
	

/*
 * END HTML
 */

/*--------------------------------------------------------------------------------------------------------------------------------------*/

/*
 * REQUEST
 */

	if ( ! function_exists('_POST'))
	{
		function _POST($str, $ifTrue = true) {
			if ( $ifTrue == true ) {
				return trim($_POST[$str]);
			}
			else {
				return $_POST[$str];
			}
		}
	}

	if ( ! function_exists('_GET'))
	{
		function _GET($str, $ifTrue = true) {
			if ( $ifTrue == true ) {
				return trim($_GET[$str]);
			}
			else {
				return $_GET[$str];
			}
		}
	}

	if ( ! function_exists('_SESSION'))
	{
		function _SESSION($str, $ifTrue = true) {
			if ( $ifTrue == true ) {
				return trim($_SESSION[$str]);
			}
			else {
				return $_SESSION[$str];
			}
		}
	}
	
	if ( ! function_exists('r_post'))
	{
		function r_post() {
			return r_print($_POST);
		}
	}
	
	if ( ! function_exists('r_get'))
	{
		function r_get() {
			return r_print($_GET);
		}
	}
	
	if ( ! function_exists('r_request'))
	{
		function r_request() {
			return r_print($_REQUEST);
		}
	}
	
	if ( ! function_exists('r_session'))
	{
		function r_session() {
			return r_print($_SESSION);
		}
	}
	
	if ( ! function_exists('r_cookies'))
	{
		function r_cookies() {
			return r_print($_COOKIES);
		}
	}

/*
 * END REQUEST
 */

/*--------------------------------------------------------------------------------------------------------------------------------------*/

/*
 * ALERT
 */
 
	if ( ! function_exists('n_record'))
	{
		function n_record() {
			return array();
		}
	}
	
	if ( ! function_exists('r_print'))
	{
		function r_print($str) {
			echo "<br/><br/><br/><pre>"; print_r($str); echo "</pre>";
		}
	}
	
	if ( ! function_exists('r_fileExists'))
	{
		function r_file_exists($file) {
			if ( file_exists($file) ) {
				echo "<strong>File Exist:</strong> \"" . $file . "\"";
			}
			else {
				echo "<strong>File Not Found:</strong> \"" . $file . "\"";
			}
		}
	}
	
	if ( ! function_exists('r_alert'))
	{
		function r_alert($str) {
			echo "<script type='text/javascript'>alert(\"".$str."\");</script>"; 
		}
	}

/*
 * END ALERT
 */

/*--------------------------------------------------------------------------------------------------------------------------------------*/

/*
 * INCLUDES
 */

	if ( ! function_exists('css_link'))
	{
		function css_link($str) {
			echo "<link href='".$str."' rel='stylesheet' type='text/css' />"; 
		}
	}
	
	if ( ! function_exists('JS_Link'))
	{
		function js_link($str) {
			echo "<script type='text/javascript' src='".$str."'></script>"; 
		}
	}

/*
 * END INCLUDES
 */

/*--------------------------------------------------------------------------------------------------------------------------------------*/

/*
 * JAVASCRIPT
 */

	if ( ! function_exists('js_script'))
	{
		function js_script($str) {
			echo "<script type='text/javascript'>" . $str . "</script>"; 
		}
	}

/*
 * END JAVASCRIPT
 */

/*--------------------------------------------------------------------------------------------------------------------------------------*/

/*
 * ESCAPE STRING
 */

	if ( ! function_exists('escapestring'))
	{
		function escapestring($str) {
			if(!get_magic_quotes_gpc()) {
				$str = mysql_escape_string($str);
			}
			return $str;
		}
	}

/*
 * END ESCAPE STRING
 */

/*--------------------------------------------------------------------------------------------------------------------------------------*/

/*
 * LINKER
 */
 
	if ( ! function_exists('redirect'))
	{
		function redirect($uri = '', $method = 'location', $http_response_code = 302)
		{
			switch($method)
			{
				case 'refresh'	: header("Refresh:0;url=".$uri);
					break;
				default			: header("Location: ".$uri, TRUE, $http_response_code);
					break;
			}
			exit;
		}
	}

/*
 * END LINKER
 */

/*--------------------------------------------------------------------------------------------------------------------------------------*/

/*
 * SESSION
 */

	if ( ! function_exists('r_destroy'))
	{
		function r_destroy($url) {
			session_destroy();
			redirect($url);
		}
	}
	
	if ( ! function_exists('_destroy'))
	{
		function _destroy() {
			session_destroy();
		}
	}
	
	if ( ! function_exists('_unset'))
	{
		function _unset($session) {
			if ( is_array($session) ) {
				foreach($session as $sessionVal) {
					unset($_SESSION[$sessionVal]);
				}
			}
			else {
				unset($_SESSION[$session]);
			}
		}
	}

/*
 * END SESSION
 */

/*--------------------------------------------------------------------------------------------------------------------------------------*/

/*
 * DATE
 */
	
	#get Month
	if ( ! function_exists('m'))
	{
		function m($date) {
			$date_format = ($date == '0000-00-00' || $date == NULL || $date == '--' || $date == '1970-01-01') ? FALSE : date('m', strtotime($date));
			return $date_format;
		}
	}
	
	#get Date
	if ( ! function_exists('d'))
	{
		function d($date) {
			$date_format = ($date == '0000-00-00' || $date == NULL || $date == '--' || $date == '1970-01-01') ? FALSE : date('d', strtotime($date));
			return $date_format;
		}
	}
	
	#get Year
	if ( ! function_exists('y'))
	{
		function y($date) {
			$date_format = ($date == '0000-00-00' || $date == NULL || $date == '--' || $date == '1970-01-01') ? FALSE : date('Y', strtotime($date));
			return $date_format;
		}
	}
	
	#birthday format (10:02 am)
	if ( ! function_exists('Hs'))
	{
		function Hs($strDate = NULL) {
			
			if ( $strDate === NULL ) {
				return date("h:i a");
			}
			else {
				return date("h:i a", strtotime($strDate));
			}
		}
	}
	#birthday format (10:02 am)
	if ( ! function_exists('monthLabel'))
	{
		function monthLabel($strNumber) {
			
			switch($strNumber) {
				case '01': case '1': return 'January'; 		break;
				case '02': case '2': return 'February'; 	break;
				case '03': case '3': return 'March'; 		break;
				case '04': case '4': return 'April'; 		break;
				case '05': case '5': return 'May'; 			break;
				case '06': case '6': return 'June'; 		break;
				case '07': case '7': return 'July'; 		break;
				case '08': case '8': return 'August'; 		break;
				case '09': case '9': return 'September'; 	break;
				case '10': 			 return 'October'; 		break;
				case '11': 			 return 'November'; 	break;
				case '12': 			 return 'December'; 	break;
			}
			
		}
	}
	
	#birthday format (2012-01-01 12:00:00)
	if ( ! function_exists('YmdHis'))
	{
		function YmdHis($strDate = NULL) {
			
			if ( $strDate === NULL )
				return date("Y-m-d H-i-s");
			else {
				return date("Y-m-d H-i-s", strtotime($strDate));
			}
		}
	}
	
	if ( ! function_exists('timeDiff'))
	{
		function timeDiff($dateFrom, $dateTo = NULL) {
			
			$dateTo 	= (($dateTo === NULL) 	? (time()) 		: ($dateTo));
			$dateTo 	= ((is_int($dateTo)) 	? ($dateTo) 	: (strtotime($dateTo)));
			$dateFrom 	= ((is_int($dateFrom)) 	? ($dateFrom) 	: (strtotime($dateFrom)));
			
			$units = array("year"   => 29030400, // seconds in a year   (12 months)
						   "month"  => 2419200,  // seconds in a month  (4 weeks)
						   "week"   => 604800,   // seconds in a week   (7 days)
						   "day"    => 86400,    // seconds in a day    (24 hours)
						   "hour"   => 3600,     // seconds in an hour  (60 minutes)
						   "minute" => 60,       // seconds in a minute (60 seconds)
						   "second" => 1         // 1 second
						   );
			
			$time_diff 	= abs($dateFrom - $dateTo);
			$diff 		= abs($dateFrom - $dateTo);
			$output = '';
			foreach($units as $unit => $mult) {
				if ( $diff >= $mult ) {
					$output .= ":".str_pad(intval($diff / $mult), 2, '0', STR_PAD_LEFT);
					$diff -= intval($diff / $mult) * $mult;
				}
				elseif ( $diff == 0 ) {
					$output .= ':00';
				}
			}
			$output = substr($output, strlen(":"));
			if ( $time_diff < 60 && $time_diff > 0 ) {
				$output = '00:'.$output;
			}
			elseif ( $time_diff == 0 ) {
				$output = '00:00';
			}
		
			return $output;
		}
	}
 
	#birthday format (January, 01, 2011)
	if ( ! function_exists('FdY'))
	{
		function FdY($date) {
			$date_format = ($date == '0000-00-00' || $date == NULL || $date == '--' || $date == '1970-01-01') ? FALSE : date('F d, Y', strtotime($date));
			return $date_format;
		}
	}
	#birthday format (01/01/2011)
	if ( ! function_exists('mdY'))
	{
		function mdY($date) {
			$date_format = ($date == '0000-00-00' || $date == NULL || $date == '--' || $date == '1970-01-01') ? FALSE : date('m/d/Y', strtotime($date));
			return $date_format;
		}
	}
	
	#birthday format (01011988000000)
	if ( ! function_exists('encryptDate'))
	{
		function encryptDate() {
			return date("mdyihs");
		}
	}
	
	#birthday format (Jan. 01, 2011)
	if ( ! function_exists('shortMdY'))
	{
		function shortMdY($date) {
			$date_format = ($date == '0000-00-00' || $date == NULL || $date == '--' || $date == '1970-01-01') ? FALSE : date('M. d, Y', strtotime($date));
			return $date_format;
		}
	}
	
	#birthday format (Jan. 01, 2011 10:00 am)
	if ( ! function_exists('shortMdYwithTime'))
	{
		function shortMdYwithTime($date) {
			$date_format = ($date == '0000-00-00' || $date == NULL || $date == '--' || $date == '1970-01-01') ? FALSE : date('M. d, Y h:i a', strtotime($date));
			return $date_format;
		}
	}
	
	#birthday format (Jan. 01, 2011 - 10:00 am (Mon))
	if ( ! function_exists('shortMdYwithTimeDay'))
	{
		function shortMdYwithTimeDay($date) {
			$date_format = ($date == '0000-00-00' || $date == NULL || $date == '--' || $date == '1970-01-01') ? FALSE : date('m/d/Y - h:i a (D)', strtotime($date));
			return $date_format;
		}
	}
	
	#birthday format (2012-12-31)
	if ( ! function_exists('Ymd'))
	{
		function Ymd($date) {
			$date_format = ($date == '0000-00-00' || $date == NULL || $date == '--' || $date == '1970-01-01') ? FALSE : date('Y-m-d', strtotime($date));
			return $date_format;
		}
	}
	#birthday format (12-31-2012)
	if ( ! function_exists('mdYDashed'))
	{
		function mdYDashed($date = NULL) {
			if ($date === NULL) {
				$date_format = FALSE;
			}
			else {
				$date_explode = explode('-', $date);
				$date_format = $date_explode[2] . '-' . $date_explode[0] . '-' . $date_explode[1];
			}
			return $date_format;
		}
	}
	#birthday format (08/08/2012)
	if ( ! function_exists('mdyFormat'))
	{
		function mdyFormat($date) {
			$date_format = ($date == '0000-00-00' || $date == NULL || $date == '--' || $date == '1970-01-01') ? FALSE : date('m/d/Y', strtotime($date));
			return $date_format;
		}
	}
	
	#birthday format (Wednesday, March 01, 2012)
	if ( ! function_exists('lFdY'))
	{
		function lFdY($date) {
			$date_format = ($date == '0000-00-00' || $date == NULL || $date == '--' || $date == '1970-01-01') ? FALSE : date('l F d, Y', strtotime($date));
			return $date_format;
		}
	}
	#birthday format (Wed. March 3, 2012 10:11:23)
	if ( ! function_exists('contactsDate'))
	{
		
		function contactsDate($dateStr) {
		
			$dateHs 	= date("Y-m-d", strtotime($dateStr));
			$dateWeek = date("Y-m-d", strtotime("-1 week"));
			$date 	= date("Y-m-d");
			
			if ( ($dateHs == '0000-00-00' || $dateHs == NULL || $date == '--' || $dateHs == '1970-01-01') ) {
				$date_format = " - - - ";
			}
			elseif ( $dateHs == $date ) {
				$date_format = "Today " . date("H:s", strtotime($dateStr)) ;
			}
			elseif ( ($dateHs < $date) && ($dateHs > $dateWeek)) {
				$date_format = date("l H:s", strtotime($dateStr));
			}
			else {
				$date_format = date("M. d, Y H:s", strtotime($dateStr));
			}
		
			return $date_format;
		}
	}
/*

	DAYS 
	d - day of the month 2 digits (01-31) 
	j - day of the month (1-31) 
	D - 3 letter day (Mon - Sun) 
	l - full name of day (Monday - Sunday) 
	N - 1=Monday, 2=Tuesday, etc (1-7) 
	S - suffix for date (st, nd, rd) 
	w - 0=Sunday, 1=Monday (0-6) 
	z - day of the year (1=365)
	
	WEEK 
	W - week of the year (1-52)
	
	MONTH 
	F - Full name of month (January - December)
	m - 2 digit month number (01-12) 
	n - month number (1-12) 
	M - 3 letter month (Jan - Dec) 
	t - Days in the month (28-31)
	
	YEAR
	L - leap year (0 no, 1 yes)
	o - ISO-8601 year number (Ex. 1979, 2006)
	Y - four digit year (Ex. 1979, 2006)
	y - two digit year (Ex. 79, 06)
	
	TIME
	a - am or pm
	A - AM or PM
	B - Swatch Internet time (000 - 999)
	g - 12 hour (1-12)
	G - 24 hour c (0-23)
	h - 2 digit 12 hour (01-12)
	H - 2 digit 24 hour (00-23)
	i - 2 digit minutes (00-59)
	s 0 2 digit seconds (00-59)
	
	OTHER e - timezone (Ex: GMT, CST)
	I - daylight savings (1=yes, 0=no)
	O - offset GMT (Ex: 0200)
	Z - offset in seconds (-43200 - 43200)
	r - full RFC 2822 formatted date

*/

/*
 * END DATE
 */

?>